<?php
$this->session->set_flashdata('num',10);
?>
<script type="text/javascript">
function prueba(){
var anos; 
  var num = $("#fecha2").val().substring(0,2);
 return anos =  $("#fecha2").val().substring(6,10)+','+num+','+$("#fecha2").val().substring(3,5);
   	
} 
</script>
<div id="error"><?php 
     $var = site_url().'/trancrearcompania/dataps/'.$this->session->userdata('LOGGED_USR_ID');
    ?></div>
<script language="javascript">
    // apply filters
    var applyFilter = function(){
        jQuery("#list").setGridParam({
            url: '<?php echo $var ?>',
            page:1,
            postData:{
                search: true,
                name: $('#name').val(),
                dispara_fin:$('.f_fin:checked').val()
            }
        });
    }

    jQuery(document).ready(function(){
        jQuery("#list").jqGrid({
       	 url: '<?php echo $var?>',
            mtype: 'POST',
            datatype: 'json',
            colNames:['ID','Referencia', 'Tipo','Jurisdic.','Registro','Dias Utr.','Etapa A.','Estatus','Etapa',
            'Total','User','Responsable','Contacto'],
            colModel :[
                {name:'IdCompania', index:'IdCompania', width:5,hidden:true},
                {name:'NombreCompania', index:'NombreCompania', width:20},
                {name:'IdServicio', index:'IdServicio', width:10},
                {name:'IdJurisdiccion', index:'IdJurisdiccion', width:8},
            	{name:'FechaUsrCompania', index:'FechaUsrCompania', width:11},
            	{name:'dias', index:'NombreCompania', width:8},
            	{name:'IdEtapa',index:'idStatu',width:6},
            	{name:'IdEstatus',index:'idStatu',width:7},
            	{name:'Etapa', index:'Etapa', width:7},
            	{name:'Total', index:'Total', width:7},
            	{name:'User', index:'User', width:7},
            	{name:'Responsable', index:'Responsable', width:7},
            	{name:'conctato', index:'Responsable', width:7}		
                ],
            pager: jQuery('#pager'),
            hiddengrid: true,
            sortname: 'IdCompania',
            rowNum:50,       
            rowList:[50,100,150],
            sortorder: "DESC",
            height: '100%',
            width: '626',
            imgpath: _base_url + 'public/css/jqgrid/flex/images',
            viewrecords: true,
            multiselect: false,
            onSelectRow: function(ids) 
            {
            	if(ids != null) 
            	{
            		var rec = jQuery("#list").getRowData(ids);
            		lol=ids;
            		
            		jQuery("#list_etapas").setGridParam({url : 'http://company24h.com/c24h/index.php/trancrearcompania/procesos_data', page : 1, mtype:'POST',postData:{id_compania:rec.IdCompania}}).setCaption("Etapas: " + rec.IdCompania).trigger('reloadGrid');
            	
            	}
            },
            adjacents: 4,
            jsonReader: { repeatitems : false, IdCompania: "0" }
        }).navGrid('#pager',{add:false,del:false,edit:false,search:false,position:"left"})
        
        .navButtonAdd('#pager',{caption:"", buttonimg: _base_url + "public/css/jqgrid/flex/images/tab_close-on.gif", onClickButton:function()
        {
        	var id=lol;
        	
        	if(id.length>0)
        	{
        		
        			var ret=jQuery("#list").getRowData(id);
        			var msg="Realmente desea finalizar este servicio?";
        			jConfirm(msg,"Dialogo de confirmacion",function(r)
        			{
        				if(r)
        				{
        					var ids_final=new Array();
        					for (var i = 0; i < id.length; i++)
        					{
                        		var ret = jQuery("#list").getRowData(id[i]);
                        		ids_final[i] = ret.IdCompania;
                    		}
                    		$.post( _site_url + '/trancrearcompania/finalizar', { final_rows: ids_final.join("|") }, function(data){
                        	$('#error').html(data); jQuery("#list").setGridParam({ postData:{ search: false }}).trigger("reloadGrid");$('#list_etapas').clearGridData();
                        	
                    		});
                    		
        				}	
        			}
        			)
        		
        		
        	}
        	else
        	{
        		jAlert("Debe seleccionar una Compania");
        	}
        	
        }
         })
        
           <?php if ($this->session->userdata('LOGGED_DEPAR') == 4 || $this->session->userdata('LOGGED_DEPAR') == 1) {
           	
           ?>
        
          .navButtonAdd('#pager',{caption:"", buttonimg: _base_url + "public/img/icons/page_white_delete.png", onClickButton:function()
         
         { var id = jQuery('#list').getGridParam('selarrrow');
         var id=lol;
        if (id.length > 0) 
        {
            if(id.length == 1)
            {
                var ret = jQuery("#list").getRowData(id);
        
                window.location = _site_url + '/main_tran/hsegui/' + ret.IdCompania;
            } else {
            	
            	 var ret = jQuery("#list").getRowData(id);
        
                window.location = _site_url + '/main_tran/hsegui/' + ret.IdCompania;
            }
        } else { jAlert('Debe seleccionar al menos una compania'); }
        return false; } })
        <?php
           }
        ?>
          
         .navButtonAdd('#pager',{caption:"", buttonimg: _base_url + "public/images/folder.gif", onClickButton:function(){ window.location = _site_url + "/lote/nulote"; } })
         .navButtonAdd('#pager',{caption:"", buttonimg: _base_url + "public/css/jqgrid/flex/images/text_columns.png", onClickButton:function(){ jQuery("#list").setColumns();} })
         
         .navButtonAdd('#pager',{caption:"Agregar", buttonimg: _base_url + "public/images/new.png", onClickButton:function(){ window.location = _site_url + "/trancrearcompania"; } })

         .navButtonAdd('#pager',{caption:"Detalle", buttonimg: _base_url + "public/images/new.png", onClickButton:function(){ window.location = _site_url + "/etapastrx/detalles"; } })
         
         .navButtonAdd('#pager',{caption:"Editar", buttonimg: _base_url + "public/images/edit.png", onClickButton:function()
         
         { var id = jQuery('#list').getGridParam('selarrrow');
         var id=lol;
        if (id.length > 0) 
        {
            if(id.length == 1)
            {
                var ret = jQuery("#list").getRowData(id);
        
                window.location = _site_url + '/main_tran/edit/' + ret.IdCompania;
            } else {
            	
            	 var ret = jQuery("#list").getRowData(id);
        
                window.location = _site_url + '/main_tran/edit/' + ret.IdCompania;
            }
        } else { jAlert('Debe seleccionar al menos una compania'); }
        return false; } }).
        
        
        navButtonAdd('#pager',{caption:"Eliminar", buttonimg: _base_url + "public/images/delete.png", onClickButton:function(){ var id=lol;
        
        if (id.length > 0) {
            var msg = '';
            if(id.length == 1) msg = 'Realmente desea eliminar esta servicio?';
            else  msg = 'Realmente desea eliminar esta servicio?';
            jConfirm(msg, 'Dialogo de Confirmacion', function (r) {
            	 
                if(r) {
                	$('#list_etapas').trigger('reloadGrid');
                    var ids_to_delete = new Array();
                    for (var i = 0; i < id.length; i++){
                        var ret = jQuery("#list").getRowData(id[i]);
                        ids_to_delete[i] = ret.IdCompania;
                    }
                     var ret = jQuery("#list").getRowData(id);
                    $.post( _site_url + '/main_tran/delete', { delete_rows: ret.IdCompania}, function(data){
                        $('#error').html(data); jQuery("#list").setGridParam({ postData:{ search: false }}).trigger("reloadGrid");$('#list_etapas').clearGridData();
                    });
                }
            });
        } else { jAlert('Debe seleccionar al menos una compania'); }

        return false;} })
        <?php   
           if ($this->session->userdata('LOGGED_ROL')==1)
           {
        ?>
       .navButtonAdd('#pager',{caption:"Limpiar", buttonimg: _base_url + "public/images/new.png", onClickButton:function(){ window.location = _site_url + "/trancrearcompania/trucate"; } });
      <?php }?>
       
        $('#apply_filter').bind('click', applyFilter);
    });
   

 function getCheckedValue(radioObj) 
 {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length; 
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

 
 function sessionUse()
 {
 	if ($('#color').val())
 	{

 	 	
 		
 		a=$('#color').val();

 	    
 		  jQuery("#list").setGridParam({url : _site_url + '/trancrearcompania/dataps/'+a, page : 1}).trigger('reloadGrid');
 		   jQuery("#list_etapas").setGridParam({url : _site_url + '/trancrearcompania/procesos_data', page : 1}).trigger('reloadGrid');
 	     
   
 	 }
 
 		
 }
   
</script>

<?php
    $servicio = $this->mservicios->Loadservicios();
    $estapa = $this->metapas->LoadEtapas();
    $estatus = $this->mestatus->LoadEstatus();  
?>


			
<div class="table_container">
<table>
                          <?php if ($this->session->userdata('LOGGED_USR_ID') == 11) {
               	?>
                <tr>
                       <td align="center" style=""> 
                            <?php echo $this->mscore->scoreDatos(1)?>        
                       </td>
                        
                  </tr>
                  
   
                  
                  
                 <?php }?>


               <?php if ($this->session->userdata('LOGGED_USR_ID') == 12) {
               	?>
                <tr>
                       <td align="center" style=""> 
                           <?php echo $this->mscore->scoreDatos(2)?>         
                       </td>
                        
                       <td align="center" > 
                            <?php echo $this->mscore->scoreDatos(3)?>           
                       </td> 
                       
                       <td align="center" > 
                            <?php echo $this->mscore->scoreDatos(15)?>           
                       </td> 
                       
                  </tr>
                  
                   <tr>
                       <td align="center" style=""> 
                             <?php echo $this->mscore->scoreDatos(9)?>           
                       </td>
                        
                       <td align="center" > 
                            <?php echo $this->mscore->porUsuario($this->session->userdata('LOGGED_USR_ID'))?> 
                                  
                       </td> 
                       
                       <td align="center" > 
                                      
                       </td> 
                  </tr>
                  <script type="text/javascript">
	
 </script> 
                  
                  
                 <?php }elseif($this->session->userdata('LOGGED_USR_ID') == 10){?>
                  
                             <tr>
                       <td align="center" style=""> 
                            <?php echo $this->mscore->porUsuario(12)?>       
                       </td>
                        
                       <td align="center" > 
                           <?php echo $this->mscore->porUsuario(11)?>             
                       </td> 
                       
                       <td align="center" > 
                           <?php echo $this->mscore->scoreDatos(16)?>           
                       </td> 
                  </tr>
                  
                   <tr>
                       <td align="center" style=""> 
                                
                       </td>
                        
                       <td align="center" > 
                             
                       </td> 
                       
                       <td align="center" > 
                                      
                       </td> 
                  </tr>
                  <script type="text/javascript">

	
 </script> 
                 
                 <?php 
                 }else if($this->session->userdata('LOGGED_DEPAR') == 2){
                 ?>
                       <tr>
                       <td align="center" style=""> 
                            <?php echo $this->mscore->scoreDatos(11)?>          
                       </td>
                        
                       <td align="center" > 
                            <?php echo $this->mscore->scoreDatos(10)?>        
                       </td> 
                       
                       <td align="center" > 
                           <div id="chartdiv2" align="center"></div>           
                       </td> 
                  </tr>
                  
                  
         
                 
                 
                 <?php }

                        if ($this->session->userdata('LOGGED_USR_ID') == 1) {
                   ?>
                   
                    <tr>
                       <td align="center" style=""> 
                               
                       </td>
                        
                       <td align="center" > 
                           <div id="chartdiv2" align="center"></div>          
                       </td> 
                       
                       <td align="center" > 
                           <div id="chartdiv3" align="center"></div>           
                       </td> 
                   </tr>
                   
                   <tr>
                       <td align="center" style=""> 
                           <div id="chartdiv4" align="center" style="border:none	;"></div>          
                       </td>
                        
                       <td align="center" > 
                              <div id="chartdiv5" align="center" style="border:none	;"></div>
                       </td> 
                       
                       <td align="center" > 
                              <div id="chartdiv6" align="center" style="border:none	;"></div>         
                       </td> 
                  </tr>
                   
 	    <tr>
		    <td>
		     <b>Usuario:</b><select name="color" id="color">
		          <option value="8">Und. Negocio</option>
		          <option value="10">Yury Cipion</option>
		          <option value="11">Rhabeli</option>
		          <option value="12">Leticia</option>
		      </select>
		        <input type="button" value="GO" onclick="sessionUse()">
		    </td>
		</tr>
		
	<?php }?>	         
<tr>
	<td colspan="3"><?php $this->load->view('estatus_filters'); ?></td>
</tr>
<tr><td colspan="3"><br /><div id="titulo">Seguimiento de Servicios<hr /></div><br /></td></tr>
<tr>
<td colspan="3">
    <table id="list" class="scroll"></table>
    <div id="pager" class="scroll" style="text-align:center;"></div>
</td>
 </tr>
<?php $this->load->view('etapas_trx_list'); ?>
</table>
</div>
 
